package com.cq.hd.system.biz;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cq.hd.common.entity.hf.*;
import com.cq.hd.common.enums.biz.*;
import com.cq.hd.common.response.Throw;
import com.cq.hd.common.utils.*;
import com.cq.hd.system.api.dto.HfRequestRecordSaveDto;
import com.cq.hd.system.api.dto.HfVerifyDto;
import com.cq.hd.system.config.FileProperties;
import com.cq.hd.system.config.HuifuConfig;
import com.cq.hd.system.service.TbHfRequestRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;

@Component
@Slf4j
public class HfBiz {

    @Autowired
    private TbHfRequestRecordService hfRequestRecordService;

    public String imgUpload(MultipartFile file, String type) {
        try {
            File saveFile = FileUtils.save(file.getBytes(), "/" + UploadFileUseEnum.HF.getName() + "/" + type, FileProperties.serverPath);
            return HuifuConfig.imgUploadApi(saveFile, type);
        } catch (IOException ioException) {
            Throw.isBusinessException("上传失败");
        }

        return null;
    }

    public HfBusinessEnterApplyResult merchantEnt(HfBusinessEnterApply hfBusinessEnterApply) {
        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
        hfBusinessEnterApply.setReqDate(reqDate);
        hfBusinessEnterApply.setReqSeqId(reqSeqId);

        HfBusinessEnterApplyResult hfBusinessEnterApplyResult = new HfBusinessEnterApplyResult();
        String result = "", huifuId = "", applyNo = "";
        String respCode = "", respDesc = "";
        try {
            result = HuifuConfig.merchantEnterApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return hfBusinessEnterApplyResult;
            }

            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObject = jsonObject.getJSONObject("data");
            if (dataJsonObject != null) {
                respCode = dataJsonObject.getString("resp_code");
                respDesc = dataJsonObject.getString("resp_desc");
                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
                    applyNo = dataJsonObject.getString("apply_no");
                    huifuId = dataJsonObject.getString("huifu_id");
                    String tokenNo = dataJsonObject.getString("token_no");
                    if (!StringUtils.isBlank(applyNo)) {
                        hfBusinessEnterApplyResult.setApplyNo(applyNo);
                    }
                    if (!StringUtils.isBlank(huifuId)) {
                        hfBusinessEnterApplyResult.setHuiFuId(huifuId);
                    }
                    if (!StringUtils.isBlank(tokenNo)) {
                        hfBusinessEnterApplyResult.setTokenNo(tokenNo);
                    }
                }
                hfBusinessEnterApplyResult.setRespDesc(respDesc);
            }
        } catch (Exception e) {
            log.error("调用企业商户入驻接口失败", e);
        }

        // 添加汇付申请单记录（企业商户基本信息入驻，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_ENT.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
        hfRequestRecordSaveDto.setHuifuId(huifuId);
        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（企业商户基本信息入驻，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        hfBusinessEnterApplyResult.setResultData(result);
        return hfBusinessEnterApplyResult;
    }

    public HfBusinessEnterApplyResult merchantEntIndv(HfBusinessEnterApply hfBusinessEnterApply) {
        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
        hfBusinessEnterApply.setReqDate(reqDate);
        hfBusinessEnterApply.setReqSeqId(reqSeqId);

        HfBusinessEnterApplyResult hfBusinessEnterApplyResult = new HfBusinessEnterApplyResult();
        String result = "", huifuId = "", applyNo = "";
        String respCode = "", respDesc = "";
        try {
            result = HuifuConfig.merchantEnterIndvApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return hfBusinessEnterApplyResult;
            }

            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObject = jsonObject.getJSONObject("data");
            if (dataJsonObject != null) {
                respCode = dataJsonObject.getString("resp_code");
                respDesc = dataJsonObject.getString("resp_desc");
                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
                    applyNo = dataJsonObject.getString("apply_no");
                    huifuId = dataJsonObject.getString("huifu_id");
                    String tokenNo = dataJsonObject.getString("token_no");
                    if (!StringUtils.isBlank(applyNo)) {
                        hfBusinessEnterApplyResult.setApplyNo(applyNo);
                    }
                    if (!StringUtils.isBlank(huifuId)) {
                        hfBusinessEnterApplyResult.setHuiFuId(huifuId);
                    }
                    if (!StringUtils.isBlank(tokenNo)) {
                        hfBusinessEnterApplyResult.setTokenNo(tokenNo);
                    }
                }
                hfBusinessEnterApplyResult.setRespDesc(respDesc);
            }
        } catch (Exception e) {
            log.error("调用个人商户入驻接口失败", e);
        }

        // 添加汇付申请单记录（个人商户基本信息入驻，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_ENT_INDV.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
        hfRequestRecordSaveDto.setHuifuId(huifuId);
        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（个人商户基本信息入驻，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        hfBusinessEnterApplyResult.setResultData(result);
        return hfBusinessEnterApplyResult;
    }

    public HfBusinessEnterApplyResult merchantEntUpdate(HfBusinessEnterApply hfBusinessEnterApply) {
        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
        hfBusinessEnterApply.setReqDate(reqDate);
        hfBusinessEnterApply.setReqSeqId(reqSeqId);

        HfBusinessEnterApplyResult hfBusinessEnterApplyResult = new HfBusinessEnterApplyResult();
        String result = "", huifuId = "", applyNo = "";
        String respCode = "", respDesc = "";
        try {
            result = HuifuConfig.merchantEnterUpdateApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return hfBusinessEnterApplyResult;
            }

            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObject = jsonObject.getJSONObject("data");
            if (dataJsonObject != null) {
                respCode = dataJsonObject.getString("resp_code");
                respDesc = dataJsonObject.getString("resp_desc");
                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
                    applyNo = dataJsonObject.getString("apply_no");
                    huifuId = dataJsonObject.getString("huifu_id");
                    String tokenNo = dataJsonObject.getString("token_no");
                    if (!StringUtils.isBlank(applyNo)) {
                        hfBusinessEnterApplyResult.setApplyNo(applyNo);
                    }
                    if (!StringUtils.isBlank(huifuId)) {
                        hfBusinessEnterApplyResult.setHuiFuId(huifuId);
                    }
                    if (!StringUtils.isBlank(tokenNo)) {
                        hfBusinessEnterApplyResult.setTokenNo(tokenNo);
                    }
                }
                hfBusinessEnterApplyResult.setRespDesc(respDesc);
            }
        } catch (Exception e) {
            log.error("调用商户基本信息修改接口失败", e);
        }

        // 添加汇付申请单记录（商户基本信息修改，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_ENT_MODIFY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
        hfRequestRecordSaveDto.setHuifuId(huifuId);
        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（商户基本信息修改，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        hfBusinessEnterApplyResult.setResultData(result);
        return hfBusinessEnterApplyResult;
    }

    public HfBusinessEnterOpenResult merchantOpen(HfBusinessEnterApply hfBusinessEnterApply) {
        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
        hfBusinessEnterApply.setReqDate(reqDate);
        hfBusinessEnterApply.setReqSeqId(reqSeqId);

        HfBusinessEnterOpenResult hfBusinessEnterOpenResult = new HfBusinessEnterOpenResult();
        String result = "", huifuId = "", applyNo = "";
        String respCode = "", respDesc = "";
        try {
            result = HuifuConfig.merchantOpenApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return hfBusinessEnterOpenResult;
            }
            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObject = jsonObject.getJSONObject("data");

            if (dataJsonObject != null) {
                respCode = dataJsonObject.getString("resp_code");
                respDesc = dataJsonObject.getString("resp_desc");
                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
                    applyNo = dataJsonObject.getString("apply_no");
                    huifuId = dataJsonObject.getString("huifu_id");
                    String productId = dataJsonObject.getString("product_id");

                    if (!StringUtils.isBlank(applyNo)) {
                        hfBusinessEnterOpenResult.setApplyNo(applyNo);
                    }
                    if (!StringUtils.isBlank(huifuId)) {
                        hfBusinessEnterOpenResult.setHuiFuId(huifuId);
                    }
                    if (!StringUtils.isBlank(productId)) {
                        hfBusinessEnterOpenResult.setProductId(productId);
                    }
                }
                hfBusinessEnterOpenResult.setRespDesc(respDesc);
            }
        } catch (Exception e) {
            log.error("调用商户业务开通接口失败", e);
        }

        // 添加汇付申请单记录（商户业务开通，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_OPEN.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
        hfRequestRecordSaveDto.setHuifuId(huifuId);
        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（商户业务开通，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        hfBusinessEnterOpenResult.setResultData(result);
        return hfBusinessEnterOpenResult;
    }

//    public HfBusinessEnterOpenResult merchantOpenModify(HfBusinessEnterApply hfBusinessEnterApply) {
//        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
//        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
//        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
//        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
//        hfBusinessEnterApply.setReqDate(reqDate);
//        hfBusinessEnterApply.setReqSeqId(reqSeqId);
//
//        HfBusinessEnterOpenResult hfBusinessEnterOpenResult = new HfBusinessEnterOpenResult();
//        String result = "", huifuId = "", applyNo = "";
//        String respCode = "", respDesc = "";
//        try {
//            result = HuifuConfig.merchantOpenModifyApi(hfBusinessEnterApply);
//            if (StringUtils.isBlank(result)) {
//                return hfBusinessEnterOpenResult;
//            }
//            JSONObject jsonObject = JSON.parseObject(result);
//            JSONObject dataJsonObject = jsonObject.getJSONObject("data");
//
//            if (dataJsonObject != null) {
//                respCode = dataJsonObject.getString("resp_code");
//                respDesc = dataJsonObject.getString("resp_desc");
//                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
//                    applyNo = dataJsonObject.getString("apply_no");
//                    huifuId = dataJsonObject.getString("huifu_id");
//                    String productId = dataJsonObject.getString("product_id");
//
//                    if (!StringUtils.isBlank(applyNo)) {
//                        hfBusinessEnterOpenResult.setApplyNo(applyNo);
//                    }
//                    if (!StringUtils.isBlank(huifuId)) {
//                        hfBusinessEnterOpenResult.setHuiFuId(huifuId);
//                    }
//                    if (!StringUtils.isBlank(productId)) {
//                        hfBusinessEnterOpenResult.setProductId(productId);
//                    }
//
//                }
//                hfBusinessEnterOpenResult.setRespDesc(respDesc);
//            }
//        } catch (Exception e) {
//            log.error("调用商户业务开通修改接口失败", e);
//        }
//
//        // 添加汇付申请单记录（商户业务开通修改，同步接口）
//        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
//        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_OPEN_MODIFY.getValue());
//        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
//        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
//        hfRequestRecordSaveDto.setHuifuId(huifuId);
//        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
//        hfRequestRecordSaveDto.setDataResult(result);
//        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
//        hfRequestRecordSaveDto.setRespCode(respCode);
//        hfRequestRecordSaveDto.setRespDesc(respDesc);
//        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
//        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
//        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
//        if (!saveRequestRecordState) {
//            log.error("添加汇付申请单记录失败（商户业务开通修改，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
//        }
//
//        hfBusinessEnterOpenResult.setResultData(result);
//        return hfBusinessEnterOpenResult;
//    }

    public HfBusinessEnterOpenResult merchantSettleConfig(HfBusinessEnterApply hfBusinessEnterApply) {
        LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
        String yyyyMMddHHmmss = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss");
        String reqDate = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
        String reqSeqId = yyyyMMddHHmmss + GenerateUtil.getRandomNum(5);
        hfBusinessEnterApply.setReqDate(reqDate);
        hfBusinessEnterApply.setReqSeqId(reqSeqId);

        HfBusinessEnterOpenResult hfBusinessEnterOpenResult = new HfBusinessEnterOpenResult();
        String result = "", huifuId = "", acctId = "", applyNo = "";
        String respCode = "", respDesc = "";
        try {
            result = HuifuConfig.merchantSettleConfigApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return hfBusinessEnterOpenResult;
            }
            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObject = jsonObject.getJSONObject("data");

            if (dataJsonObject != null) {
                respCode = dataJsonObject.getString("resp_code");
                respDesc = dataJsonObject.getString("resp_desc");
                if ("00000000".equals(respCode) || "90000000".equals(respCode)) {
                    applyNo = dataJsonObject.getString("apply_no");
                    huifuId = dataJsonObject.getString("huifu_id");
                    acctId = dataJsonObject.getString("acct_id");
                    String tokenNo = dataJsonObject.getString("token_no");
                    String productId = dataJsonObject.getString("product_id");

                    if (!StringUtils.isBlank(applyNo)) {
                        hfBusinessEnterOpenResult.setApplyNo(applyNo);
                    }
                    if (!StringUtils.isBlank(huifuId)) {
                        hfBusinessEnterOpenResult.setHuiFuId(huifuId);
                    }
                    if (!StringUtils.isBlank(acctId)) {
                        hfBusinessEnterOpenResult.setHfAcctId(acctId);
                    }
                    if (!StringUtils.isBlank(productId)) {
                        hfBusinessEnterOpenResult.setProductId(productId);
                    }
                    if (!StringUtils.isBlank(tokenNo)) {
                        hfBusinessEnterOpenResult.setTokenNo(tokenNo);
                    }
                }
                hfBusinessEnterOpenResult.setRespDesc(respDesc);
            }
        } catch (Exception e) {
            log.error("调用子账号开通接口失败", e);
        }

        // 添加汇付申请单记录（子账号开通，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_SETTLE_CONFIG_OPEN.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo(hfBusinessEnterApply.getApplyNo());
        hfRequestRecordSaveDto.setHuifuId(huifuId);
        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（子账号开通，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        hfBusinessEnterOpenResult.setResultData(result);
        return hfBusinessEnterOpenResult;
    }

    public Boolean verify(HfVerifyDto hfVerifyDto) {
        return HuifuConfig.verify(hfVerifyDto.getData(), hfVerifyDto.getSign());
    }

    public JSONObject basicDataQuery(String applyNo, String huiFuId) {
        try {
            String result = HuifuConfig.basicDataQueryApi(applyNo, huiFuId);
            if (StringUtils.isBlank(result)) {
                return JSON.parseObject(result);
            }
        } catch (Exception e) {
            log.error("调用申请单查询接口失败", e);
        }
        return null;
    }

    public JSONObject jsPay(HfJsPay hfJsPay) {
        String reqSeqId = hfJsPay.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);
            String timeExpire = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime.plusMinutes(40), "yyyyMMddHHmmss");

            hfJsPay.setReqSeqId(reqSeqId);
            hfJsPay.setReqDate(yyyyMMdd);
            hfJsPay.setTimeExpire(timeExpire);
        }

        String result;
        try {
            result = HuifuConfig.jsPayApi(hfJsPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用聚合正扫支付接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（聚合支付下单，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.WX_JS_ORDER.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfJsPay.getHfMerchantNo());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（聚合支付下单，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject merchantBasicDataQuery(String hfMerchantNo) {
        try {
            String result = HuifuConfig.merchantBasicDataQueryApi(hfMerchantNo);
            if (!StringUtils.isBlank(result)) {
                return JSON.parseObject(result);
            }
        } catch (Exception e) {
            log.error("调用商户详细信息查询（查询合同签约状态）接口失败", e);
        }
        return null;
    }

    public JSONObject wxBusinessRealQuery(String hfMerchantNo) {
        try {
            String result = HuifuConfig.wxBusinessRealQueryApi(hfMerchantNo);
            if (!StringUtils.isBlank(result)) {
                return JSON.parseObject(result);
            }
        } catch (Exception e) {
            log.error("调用微信实名认证状态查询接口失败", e);
        }
        return null;
    }

    public JSONObject wxBusinessConfig(String hfMerchantNo) {
        String result = "";
        try {
            result = HuifuConfig.wxBusinessConfigApi(hfMerchantNo);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用微信商户配置接口失败", e);
        }

//        // 添加汇付申请单记录（子账号开通，同步接口）
//        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
//        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_SETTLE_CONFIG_OPEN.getValue());
//        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
//        hfRequestRecordSaveDto.setApplyNo("");
//        hfRequestRecordSaveDto.setHuifuId(hfMerchantNo);
//        hfRequestRecordSaveDto.setHfApplyNo(applyNo);
//        hfRequestRecordSaveDto.setDataResult(result);
//        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
//        hfRequestRecordSaveDto.setRespCode(respCode);
//        hfRequestRecordSaveDto.setRespDesc(respDesc);
//        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
//        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
//        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
//        if (!saveRequestRecordState) {
//            log.error("添加汇付申请单记录失败（子账号开通，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
//        }

        return JSON.parseObject(result);
    }

    public JSONObject preOrder(HfJsPay hfJsPay) {
        String reqSeqId = hfJsPay.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);
            String timeExpire = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime.plusMinutes(30), "yyyyMMddHHmmss");

            hfJsPay.setReqSeqId(reqSeqId);
            hfJsPay.setReqDate(yyyyMMdd);
            hfJsPay.setTimeExpire(timeExpire);
        }

        String result;
        try {
            result = HuifuConfig.preOrderApi(hfJsPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用小程序预下单接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（微信小程序预下单，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.WX_PRE_ORDER.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfJsPay.getHfMerchantNo());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（微信小程序预下单，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeQuery(HfTradeQuery hfTradeQuery) {
        try {
            String result = HuifuConfig.tradeQueryApi(hfTradeQuery);
            if (!StringUtils.isBlank(result)) {
                return JSON.parseObject(result);
            }
        } catch (Exception e) {
            log.error("调用交易查询接口失败", e);
        }
        return null;
    }

    public JSONObject tradeRefund(HfTradeRefund hfTradeRefund) {
        String reqSeqId = hfTradeRefund.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);

            hfTradeRefund.setReqSeqId(reqSeqId);
            hfTradeRefund.setReqDate(yyyyMMdd);
        }

        String result;
        try {
            result = HuifuConfig.tradeRefundApi(hfTradeRefund);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用交易退款接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（交易退款，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.TRADE_REFUND.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfTradeRefund.getHfMerchantNo());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（交易退款，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeRefundQuery(HfTradeRefundQuery hfTradeRefundQuery) {
        String result;
        try {
            result = HuifuConfig.tradeRefundQueryApi(hfTradeRefundQuery);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用交易退款查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（交易退款查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.TRADE_REFUND_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfTradeRefundQuery.getHfMerchantNo());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（交易退款查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject agentUserInvite(HfAgentUserEnterApply hfAgentUserEnterApply) {
        String reqSeqId = hfAgentUserEnterApply.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);

            hfAgentUserEnterApply.setReqSeqId(reqSeqId);
            hfAgentUserEnterApply.setReqDate(yyyyMMdd);
        }

        String result;
        try {
            result = HuifuConfig.agentUserInviteApi(hfAgentUserEnterApply);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用个人用户开户接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（个人用户开户，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_USER_INVITE.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（个人用户开户，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject agentUserOpen(HfAgentUserEnterApply hfAgentUserEnterApply) {
        String reqSeqId = hfAgentUserEnterApply.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);

            hfAgentUserEnterApply.setReqSeqId(reqSeqId);
            hfAgentUserEnterApply.setReqDate(yyyyMMdd);
        }

        String result;
        try {
            result = HuifuConfig.agentUserOpenApi(hfAgentUserEnterApply);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用用户业务入驻接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（用户业务入驻，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_USER_OPEN.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（用户业务入驻，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject agentUserQuery(String hfId) {
        String result;
        try {
            result = HuifuConfig.agentUserQueryApi(hfId);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用用户业务查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（用户业务查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_USER_OPEN_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（用户业务查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject merchantSignQuery() {
        String result;
        try {
            result = HuifuConfig.merchantSignQueryApi();
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用商户签约查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（商户签约查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_SIGN_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（商户签约查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject agentSignCreate(HfAgentUserSignCreate hfAgentUserSignCreate) {
        String result;
        try {
            result = HuifuConfig.agentSignCreateApi(hfAgentUserSignCreate);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用个人签约发起接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（商户签约查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_SIGN_CREATE.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（个人签约发起，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject agentSignQuery(String contractId) {
        String result;
        try {
            result = HuifuConfig.agentSignQueryApi(contractId);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用个人签约查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（个人签约查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_SIGN_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（个人签约查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeAccountAmtPay(HfTradeAccountPay hfTradeAccountPay) {
        String result;
        try {
            result = HuifuConfig.tradeAccountAmtPayApi(hfTradeAccountPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用余额支付接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（余额支付，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        // 如果是灵活用工，则表示余额支付（给经纪人分佣金）,否则表示余额支付（给商户分本金）
        hfRequestRecordSaveDto.setApplyType((!StringUtils.isBlank(hfTradeAccountPay.getHycFlag()) && "Y".equals(hfTradeAccountPay.getHycFlag()))
                ? HfRequestRecordApplyTypeEnum.TRADE_AGENT_ACCOUNT_AMT_PAY.getValue()
                : HfRequestRecordApplyTypeEnum.TRADE_ACCOUNT_AMT_PAY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（余额支付，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeAccountAmtQuery(HfTradeAccountPay hfTradeAccountPay) {
        String result;
        try {
            result = HuifuConfig.tradeAccountAmtQueryApi(hfTradeAccountPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用余额支付查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（余额支付查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.TRADE_ACCOUNT_AMT_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（余额支付查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeMarketTransferPay(HfTradeMarketPay hfTradeMarketPay) {
        String result;
        try {
            result = HuifuConfig.tradeMarketTransferPayApi(hfTradeMarketPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用余额支付查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（补贴转账（给商户分补贴），同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.TRADE_MARKET_TRANSFER_PAY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（补贴转账（给商户分补贴），同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject tradeMarketTransferQuery(HfTradeMarketPay hfTradeMarketPay) {
        String result;
        try {
            result = HuifuConfig.tradeMarketTransferQueryApi(hfTradeMarketPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用余额支付查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（补贴转账查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.TRADE_MARKET_TRANSFER_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（补贴转账查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject settlement(HfSettlement hfSettlement) {
        String result;
        try {
            result = HuifuConfig.settlementApi(hfSettlement);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用结算提现接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（结算提现，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.SETTLEMENT.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（结算提现，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject settlementQuery(HfSettlement hfSettlement) {
        String result;
        try {
            result = HuifuConfig.settlementQueryApi(hfSettlement);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用结算提现查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（结算提现查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.SETTLEMENT_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（结算提现查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject hycInvCategoryQuery(String minorAgentId) {
        String result;
        try {
            result = HuifuConfig.hycInvCategoryQueryApi(minorAgentId);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用开票类目查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（开票类目查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.HYC_INV_CATEGORY_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（开票类目查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public HfInvApply hycInvApply(HfInvApply hfInvApply) {
        HfInvApply hfInvApplyResult;
        String result;
        try {
            hfInvApplyResult = HuifuConfig.hycInvApplyApi(hfInvApply);
            result = hfInvApplyResult.getResult();
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用申请开票（灵活用工）接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        // 开票批次号
        hfInvApplyResult.setInvoiceBatch(dataJSONObject.getString("invoice_batch"));

        // 添加汇付申请单记录（申请开票（灵活用工），同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.HYC_INV_APPLY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfInvApply.getHuifu_id());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(hfInvApply.getReqSeqId());
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（申请开票（灵活用工），同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return hfInvApplyResult;
    }

    public JSONObject hycInvQuery(HfInvApply hfInvApply) {
        String result;
        try {
            result = HuifuConfig.hycInvQueryApi(hfInvApply);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用申请开票（灵活用工）接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（开票信息查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.HYC_INV_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfInvApply.getHuifu_id());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(hfInvApply.getReqSeqId());
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（开票信息查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject bankPay(HfBankPay hfBankPay) {
        String result;
        try {
            result = HuifuConfig.bankPayApi(hfBankPay);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用网银支付接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");

        // 添加汇付申请单记录（网银支付，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.BANK_PAY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(hfBankPay.getHuifuId());
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(hfBankPay.getReqSeqId());
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（网银支付，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject bankPayQuery(HfTradeQuery hfTradeQuery) {
        try {
            String result = HuifuConfig.bankPayQueryApi(hfTradeQuery);
            if (!StringUtils.isBlank(result)) {
                return JSON.parseObject(result);
            }
        } catch (Exception e) {
            log.error("调用线上交易查询接口失败", e);
        }
        return null;
    }

    public JSONObject agentUserModify(HfAgentUserEnterApply hfAgentUserEnterApply) {
        String reqSeqId = hfAgentUserEnterApply.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);

            hfAgentUserEnterApply.setReqSeqId(reqSeqId);
            hfAgentUserEnterApply.setReqDate(yyyyMMdd);
        }

        String result;
        try {
            result = HuifuConfig.agentUserModifyApi(hfAgentUserEnterApply);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用用户业务入驻修改接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（用户业务入驻修改，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.AGENT_USER_OPEN_MODIFY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（用户业务入驻修改，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject acctBalanceQuery(String hfId) {
        String result;
        try {
            result = HuifuConfig.acctBalanceQueryApi(hfId);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用账户余额信息查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（账户余额信息查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.ACCT_BALANCE_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（账户余额信息查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject userBasicDataQuery(String hfId) {
        String result;
        try {
            result = HuifuConfig.userBasicDataQueryApi(hfId);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用用户信息查询接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（用户信息查询，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.USER_BASIC_DATA_QUERY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId("");
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（用户信息查询，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }

    public JSONObject merchantSettleModify(HfBusinessEnterApply hfBusinessEnterApply) {
        String reqSeqId = hfBusinessEnterApply.getReqSeqId();
        if (StringUtils.isBlank(reqSeqId)) {
            LocalDateTime nowLocalDateTime = LocalDateUtil.getNowLocalDateTime();
            String yyyyMMdd = LocalDateUtil.toLocalDateToString(nowLocalDateTime.toLocalDate(), "yyyyMMdd");
            reqSeqId = LocalDateUtil.toLocalDateTimeToString(nowLocalDateTime, "yyyyMMddHHmmss") + GenerateUtil.getRandomNum(5);

            hfBusinessEnterApply.setReqSeqId(reqSeqId);
            hfBusinessEnterApply.setReqDate(yyyyMMdd);
        }

        String result;
        try {
            result = HuifuConfig.merchantSettleModifyApi(hfBusinessEnterApply);
            if (StringUtils.isBlank(result)) {
                return null;
            }
        } catch (Exception e) {
            log.error("调用修改子账号配置接口失败", e);
            return null;
        }

        JSONObject jsonObject = JSON.parseObject(result);
        JSONObject dataJSONObject = jsonObject.getJSONObject("data");
        String respCode = dataJSONObject.getString("resp_code");
        String respDesc = dataJSONObject.getString("resp_desc");
        String huifu_id = dataJSONObject.getString("huifu_id");

        // 添加汇付申请单记录（修改子账号配置，同步接口）
        HfRequestRecordSaveDto hfRequestRecordSaveDto = new HfRequestRecordSaveDto();
        hfRequestRecordSaveDto.setApplyType(HfRequestRecordApplyTypeEnum.MERCHANT_SETTLE_MODIFY.getValue());
        hfRequestRecordSaveDto.setRequestType(HfRequestRecordRequestTypeEnum.SYNC.getValue());
        hfRequestRecordSaveDto.setApplyNo("");
        hfRequestRecordSaveDto.setHuifuId(huifu_id);
        hfRequestRecordSaveDto.setHfApplyNo("");
        hfRequestRecordSaveDto.setDataResult(result);
        hfRequestRecordSaveDto.setReqSeqId(reqSeqId);
        hfRequestRecordSaveDto.setRespCode(respCode);
        hfRequestRecordSaveDto.setRespDesc(respDesc);
        hfRequestRecordSaveDto.setCreateTime(LocalDateTime.now());
        hfRequestRecordSaveDto.setUpdateTime(LocalDateTime.now());
        Boolean saveRequestRecordState = hfRequestRecordService.saveRequestRecord(hfRequestRecordSaveDto);
        if (!saveRequestRecordState) {
            log.error("添加汇付申请单记录失败（修改子账号配置，同步接口），hfRequestRecordSaveDto：{}", JSON.toJSONString(hfRequestRecordSaveDto));
        }

        return jsonObject;
    }
}
